home *** CD-ROM | disk | FTP | other *** search
- ;void box_down(box,col,row,width,depth);
- ; unsigned char *box,*col,*row, width,depth;
-
- EXTRN _memory_model:byte
- EXTRN _video_buffer:word
- EXTRN _snow_protect:byte
-
- box_seg EQU [bp-2]
- box_ofs EQU [bp-4]
- col_seg EQU [bp-6]
- col_ofs EQU [bp-8]
- row_seg EQU [bp-10]
- row_ofs EQU [bp-12]
- width EQU [bp-14]
- depth EQU [bp-16]
- snow EQU [bp-18]
- endofbox EQU [bp-20]
- toppos EQU [bp-22]
- rghtpos EQU [bp-24]
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _box_down
- _box_down proc near
- push bp ;
- mov bp,sp ;set stack frame
- sub sp,24 ;make room to hold parameters
- pushf ;
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;save Turbo's DS
- mov dx,_video_buffer ;grab _video_buffer
- push dx ;save it
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- push [bp+6] ;move parameters to SP offsets
- push [bp+10]
- push [bp+14]
- push [bp+4]
- push [bp+8]
- push [bp+12]
- push [bp+16]
- push [bp+18]
- jmp short L00
- L0: push ds ;near case
- push ds
- push ds
- push [bp+4]
- push [bp+6]
- push [bp+8]
- mov al,[bp+10]
- sub ah,ah
- push ax
- mov al,[bp+12]
- push ax
- L00: cmp _memory_model,0 ;check code model again
- jle L000 ;jump if near
- dec bp ;unadjust BP so all BP offsets same
- dec bp ;
- L000: pop depth ;set intermediate values
- pop width
- pop row_ofs
- pop col_ofs
- pop box_ofs
- pop row_seg
- pop col_seg
- pop box_seg
- mov ax,col_seg ;ES:DI pts to Col
- mov es,ax ;
- mov di,col_ofs ;
- mov al,_snow_protect ;grab _snow_protect
- mov snow,al ;save it
- sub cx,cx ;
- mov cl,es:[di] ;get column position
- jcxz F1 ;quit if column is zero
- dec cx ;count from zero
- cmp cx,79 ;in range?
- jna G1 ;jump ahead if so
- F1: jmp M1 ;else quit
- G1: mov ax,box_seg ;segment of Box
- mov es,ax ;load in ES
- mov di,box_ofs ;offset of Box
- mov ax,depth ;depth to AX
- dec ax ;dec for test
- cmp ax,24 ;in range?
- jna H1 ;jump ahead if so
- jmp M1 ;else quit routine
- H1: inc ax ;readjust
- mov bx,width ;width to BX
- dec bx ;dec for test
- cmp bx,79 ;in range?
- jna I1 ;jump ahead if so
- jmp M1 ;else quit
- I1: inc bx ;readjust
- mul bl ;width times depth
- shl ax,1 ;double for attributes
- add ax,di ;offset to end of Box
- mov endofbox,ax ;save end of box ptr
- mov di,ax ;pt ES:DI to end of Box
- mov ax,row_seg ;point DS:SI to Row
- mov ds,ax ;
- mov si,row_ofs ;
- sub ax,ax ;
- mov al,[si] ;get row value
- dec ax ;count from zero
- cmp ax,24 ;in range?
- jna K1 ;jump ahead if so
- J1: jmp M1 ;else quit
- K1: mov bx,ax ;copy in BX
- add bx,depth ;add depth
- cmp bx,24 ;edge of screen?
- ja J1 ;quit if so
- add ax,2 ;inc old row value
- mov [si],al ;reset row variable
- sub ax,2 ;back to old value
- mov bl,160 ;bytes per row
- mul bl ;calculate row offset
- shl cx,1 ;col offset
- add ax,cx ;add to row offset
- mov si,ax ;SI pts to topleft corner
- mov toppos,si ;save it
- mov ax,dx ;_video_buffer
- mov ds,ax ;move to DS
- mov ax,depth ;get depth
- mov cl,160 ;bytes per row
- mul cl ;times depth
- add si,ax ;DS:SI pts to topright
- mov rghtpos,si ;copy
- pop bx ;_video_buffer
- cld ;set direction
- mov cx,width ;get width
- shl cx,1 ;double for attributes
- call Writeit ;write a char
- mov ax,ds ;DS to AX
- mov es,ax ;now ES pts to screen too
- mov di,rghtpos ;new bottom right pos
- mov si,di ;copy to SI
- sub si,160 ;SI one row higher
- mov ax,depth ;depth to AX
- L1: mov cx,width ;width to CX
- push di ;save target ptr
- push si ;save source ptr
- shl cx,1 ;dbl width for attributes
- call Writeit ;write a char
- pop si ;restore ptr
- pop di ;restore ptr
- sub di,160 ;ptr up one row
- sub si,160 ;ditto
- dec ax ;dec depth counter
- jnz L1 ;loop till finished
- mov ax,box_seg ;segment of Box
- mov ds,ax ;move to DS
- mov si,box_ofs ;offset of Box
- mov di,toppos ;ES:DI pts to topleft
- mov dx,width ;width
- shl dx,1 ;double for attributes
- mov cx,dx ;use as counter
- call Writeit ;write a char
- mov ax,ds ;DS pts to Box
- mov es,ax ;now ES does too
- mov di,box_ofs ;offset to start of Box
- mov si,di ;copy to SI
- add si,dx ;offset to second row
- mov ax,depth ;depth
- mov cx,width ;width
- mul cl ;size of Box
- mov cx,ax ;move to CX as counter
- rep movsw ;shift all upwards
- jmp short N1 ;jump to end
- M1: pop bx ;balance stack if error
- N1: sti ;reenable interrupts
- pop ds ;
- pop si ;
- pop di ;
- popf ;
- add sp,24 ;restore stack pointer
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _box_down endp
- Writeit PROC
- push dx ;save DX
- push ax ;save AX
- mov dx,3dah ;status byte address
- mov bx,es ;get target segment
- mov ax,ds ;get source segment
- cmp ax,bx ;is source larger?
- jna A1 ;jump if not
- mov bx,ax ;else use source
- A1: cmp byte ptr snow,0 ;protect against snow?
- je D1 ;jump ahead if not
- B1: in al,dx ;get status byte
- test al,1 ;test bit
- jnz B1 ;loop till 0
- cli ;disable interrupts
- C1: in al,dx ;get status byte
- test al,1 ;test bit
- jz C1 ;loop till 1
- D1: movsb ;move a character
- loop A1 ;go do next
- pop ax ;restore AX
- pop dx ;restore DX
- ret ;
- Writeit endp
- _TEXT ENDS
- END